<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-08-15 16:45:26
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2023-03-29 19:40:56
 * @FilePath: \grazlink20\uc_sys\src\views\UserCenter\Org\components\Examine.vue
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved. 
-->
<script setup lang="ts">
import { reactive, ref, unref } from 'vue'
import { LeeEdit } from '@/components/Lee/Edit'
import { LeeSee } from '@/components/Lee/See'
import { ucRoleListApi } from '@/api/uc/role'
import { required } from '@/utils/formRules'
// 获取字典
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
const dict: any = wsCache.get('dict')

defineProps({
  data: {
    type: Object as any,
    default: () => null
  }
})

const editData = reactive({})

const rules = reactive({
  owner_sys_role_id: [required],
  state: [required]
})

// const typeChange = (value) => {
//   data.value.terminal_type = value
// }

const newSysRoleData = ref<any[]>([])
const editSchema = reactive<FormSchema[]>([
  // {
  //   field: 'owner_sys_role_id',
  //   label: '分配系统角色',
  //   component: 'TreeSelect',
  //   componentProps: {
  //     data: newSysRoleData,
  //     'check-strictly': true,
  //     'default-expand-all': true,
  //     'node-key': 'role_id',
  //     props: {
  //       children: 'children',
  //       label: 'role_name'
  //     }
  //   },
  //   colProps: {
  //     span: 24
  //   }
  // },
  {
    field: 'terminal_type',
    label: '分配终端',
    component: 'Select',
    componentProps: {
      options: dict.terminal_type
      // onChange: typeChange
    }
  },
  {
    field: 'state',
    label: '审核结果',
    component: 'Radio',
    componentProps: { options: dict.org_examine },
    colProps: {
      span: 24
    }
  }
])

const seeSchema = reactive<any>([
  {
    field: 'org_name',
    label: '组织名称'
  },
  {
    field: 'org_type',
    label: '组织类型',
    component: 'Dict',
    componentProps: { options: dict.org_type }
  },
  {
    field: 'state',
    label: '审核状态',
    component: 'Dict',
    componentProps: { options: dict.org_state }
  },
  {
    field: 'is_stop',
    label: '是否停用',
    component: 'Dict',
    componentProps: { options: dict.is }
  },
  {
    field: 'business_license',
    label: '营业执照',
    span: 2
  },
  {
    field: 'business_license_img',
    label: '营业执照照片地址',
    span: 2,
    component: 'Image'
  },
  {
    field: 'identity_card',
    label: '身份证号',
    span: 2
  },
  {
    field: 'identity_card_front',
    label: '身份证正面照片',
    span: 2,
    component: 'Image'
  },
  {
    field: 'identity_card_back',
    label: '身份证反面照片',
    span: 2,
    component: 'Image'
  }
])

// 获取所有系统角色
const getSysRole = async () => {
  let res = await ucRoleListApi({ is_sys: 1 })
    .catch(() => {})
    .finally(() => {})
  if (res) {
    newSysRoleData.value = res.data
  }
}
// 初始化
const init = async () => {
  // 获取所有系统角色
  await getSysRole()
}
init()

const leeEditRef = ref<ComponentRef<typeof LeeEdit>>()
const elFormRef = () => {
  return unref(leeEditRef)?.elFormRef
}
const getData = async () => {
  return await unref(leeEditRef)?.getFormData()
}
defineExpose({
  elFormRef,
  getData
})
</script>

<template>
  <div>
    <LeeSee :schema="seeSchema" :data="data" />
    <LeeEdit ref="leeEditRef" :schema="editSchema" :data="editData" :rules="rules" />
  </div>
</template>
